package school30;

import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;

class MainCanvas extends Canvas
        implements Runnable {
    //private int[] buffer; (Not actual anymore)

    private static Image mainImage;
    private static Graphics mainGraphics;
    Display display; // the display for the application

    public MainCanvas(Display d, int[] rgbData) {
        display = d;
        mainImage = Image.createImage(getWidth(), getHeight());
        mainGraphics = mainImage.getGraphics();
        setFullScreenMode(true);
    }

    public void paint(Graphics g) {
        g.drawImage(mainImage, 0, 0, 0);
    }

    public void startAnimation() {
        repaint();
        display.callSerially(this);
    }

    public void run() {
        if (true) {
            repaint();
            display.callSerially(this);
        }
    }

    protected void showNotify() {
        shown = true;
        System.out.println("shown");
    }

    protected void hideNotify() {
        shown = false;
        System.out.println("hidden");
    }

    static Graphics getMainGraphics() {
        return mainGraphics;
    }

    protected void keyPressed(int keyCode) {
        MainMIDlet.mainMIDlet.keyPressed(keyCode);
    }

    protected void keyReleased(int keyCode) {
        MainMIDlet.mainMIDlet.keyReleased(keyCode);
    }
    boolean shown = false;
}
